var SF_MOB = {
	load : function () {
		var sidebarButtons = document.getElementById("sf-toolbar").getElementsByTagName("toolbarbutton");
		var len = sidebarButtons.length;
		
		for (var i = 0; i < len; i++) {
			var button = sidebarButtons[i];
			
			button.setAttribute("oncommand", "SF_MOB.toolbarButtonPress("+i+");");
		}
		
		this.toolbarButtonPress(0);
	},
	
	toolbarButtonPress : function (index) {
		var screens = document.getElementById("scribefire-screens").childNodes;
		var len = screens.length;
		
		for (var i = 0; i < len; i++) {
			if (i != index) {
				screens[i].style.display = 'none';
			}
		}
		
		screens[index].style.display = '';
		screens[index].style.width = '100%';
		
		var buttons = document.getElementById("sf-toolbar").getElementsByTagName("toolbarbutton");
		var len = buttons.length;
		
		for (var i = 0; i < len; i++) {
			if (i != index) {
				buttons[i].removeAttribute("active");
			}
		}
		
		if (index < buttons.length) {
			buttons[index].setAttribute("active", "active");
		}
	}
};

addEventListener("load", function () { SF_MOB.load(); }, false);